"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.noChinese = exports.inputTrim = exports.toFixedMoney = exports.toFixedNumber = exports.semicolon = void 0;

/**
 * 添加千分号
 * @param {*} value
 */
var semicolon = function semicolon(value) {
  if (value === 0) {
    return '0';
  }

  if (!value) {
    return '';
  }

  if (value === 'NaN') {
    return '';
  }

  if ("".concat(value).split('.').length > 1) {
    return "".concat(value).replace(/(\d)(?=(\d{3})+\.)/g, '$1,');
  }

  return "".concat(value).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
};
/**
 * 格式化保留小数位
 * @param {number} num 需要格式化的数字
 * @param {number} length 需要保留长度
 */


exports.semicolon = semicolon;

var toFixedNumber = function toFixedNumber(num) {
  var length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;

  if (!num && num !== 0) {
    return '';
  }

  return semicolon(Number(num).toFixed(length));
};
/**
 * 格式化金额小数位
 * @param {number} num 需要格式化的数字
 * @param {number} length 需要保留长度
 */


exports.toFixedNumber = toFixedNumber;

var toFixedMoney = function toFixedMoney(num) {
  var length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;

  if (!num && num !== 0) {
    return '';
  }

  return semicolon(Number(num).toFixed(length));
}; // input trim


exports.toFixedMoney = toFixedMoney;

var inputTrim = function inputTrim(e) {
  var value = String(e.target.value).trim();
  return value;
};

exports.inputTrim = inputTrim;

var noChinese = function noChinese(e) {
  var value = String(e.target.value).replace(/[^\w\d-/]/g, '');
  return value;
};

exports.noChinese = noChinese;
var _default = {};
exports.default = _default;